package py.com.alfa.escriba.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ConfigLocator {

	private Logger log = LoggerFactory.getLogger(getClass());
	//	private EscilaConfig config = null;
	private String serverPath = null;
	private String filePath = null;
	private String beanConfig = null;

	public ConfigLocator() {
		this.init();
	}

	public void init() {
		log.info("\n======= LOCATING APPLICATION CONFICURATION =======\n");
		serverPath = System.getProperty("jboss.server.home.dir");
		if(null != serverPath){
			log.info("---JBOSS AS5 CONFIG");
			loadConfig();
			return;
		}
		serverPath = System.getProperty("jboss.server.config.dir");
		if(null != serverPath){
			log.info("---JBOSS AS7 CONFIG");
			loadConfig();
			return;
		}
		serverPath = System.getProperty("catalina.base");
		if(null != serverPath){
			log.info("---TOMCAT CONFIG");
			loadConfig();
			return;
		}
		log.error("CAN'T LOAD SYSTEM CONFIG - PLEASE VERIFY THE LOCATION OF YOUR CONFIG FILE");
	}

	private void loadConfig(){
		log.info("::::LOADING CONFIG::::");
		filePath = serverPath.concat("/conf");
	}

	/**
	 * @return the serverPath
	 */
	public String getServerPath() {
		return serverPath;
	}

	/**
	 * @param serverPath the serverPath to set
	 */
	public void setServerPath(String serverPath) {
		this.serverPath = serverPath;
	}

	/**
	 * @return the filePath
	 */
	public String getFilePath() {
		return filePath;
	}

	/**
	 * @param filePath the filePath to set
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	/**
	 * @return the beanConfig
	 */
	public String getBeanConfig() {
		return beanConfig;
	}

	/**
	 * @param beanConfig the beanConfig to set
	 */
	public void setBeanConfig(String beanConfig) {
		this.beanConfig = beanConfig;
	}

}
